import axios from 'axios';
import { Message } from 'element-ui';
import { getCookie } from './support';
const apiurl = process.env.VUE_APP_API_URL;
console.log(apiurl);
console.log(process.env.NODE_ENV)
const service = axios.create({
    baseURL: apiurl + "/index/Api",
    // baseURL:'http://www.yinruifang.cn/index/Api',
    timeout:60*1000
})
service.interceptors.request.use(config=>{
    config.headers.Authorization = getCookie('token');
    return config;

    },
    err =>{
        return Promise.reject(err)
    }

)
service.interceptors.response.use(res=>{
    console.log(res);
    const data = res.data;
    if (data.status !== 200){
        Message({
            type:'error',
            message:data.msg,
            duration:2000
        })
    }else{
        return data 
        }
    },
    err =>{
        console.log(err);
        Message({
            type:"error",
            message:err,
            duration:2000
        })
    }
)
export default service